package com.bluesky.android.webservice;

import java.util.ArrayList;
import java.util.List;

import org.ksoap2.serialization.SoapObject;

public class MangaStoryDetail extends MangaStory {

	public MangaStoryDetail(String link, String title, String author,
			String imageLink, String summay) {
		super(link, title, author, imageLink, summay);
		this.listChapters = new ArrayList<MangaChapter>();
	}
	
	public MangaStoryDetail(String link, String title, String author,
			String imageLink, String summay, List<MangaChapter> listChapters) {
		super(link, title, author, imageLink, summay);
		this.listChapters = listChapters;
	}
	
	public static MangaStoryDetail GetMangaStoryDetailFromSoapObject(SoapObject soapObject){
		MangaStoryDetail mangaStoryDetail = new MangaStoryDetail();
		if(soapObject.getProperty("Author") != null)
		{
			mangaStoryDetail.setAuthor(soapObject.getProperty("Author").toString() );
		}
		if(soapObject.getProperty("ImageLink") != null)
		{
			mangaStoryDetail.setImageLink(soapObject.getProperty("ImageLink").toString());
		}
		if(soapObject.getProperty("Link") != null)
		{
			mangaStoryDetail.setLink(soapObject.getProperty("Link").toString());
		}
		if(soapObject.getProperty("Summary") != null)
		{
			mangaStoryDetail.setSummary(soapObject.getProperty("Summary").toString());
		}
		if(soapObject.getProperty("Title") != null)
		{
			mangaStoryDetail.setTitle(soapObject.getProperty("Title").toString());
		}
		if(soapObject.getProperty("Chapters") != null)
		{
			SoapObject chaptersObject =(SoapObject) soapObject.getProperty("Chapters");
			int coutnOfChapterInList = chaptersObject.getPropertyCount();
			for(int i =0; i<coutnOfChapterInList; i++)
			{
				MangaChapter chapter = MangaChapter.GetMangaChapterFromSoapObject( (SoapObject)chaptersObject.getProperty(i) );
				mangaStoryDetail.getListChapters().add(chapter);
			}
			 
		}
		
    	return mangaStoryDetail;
	}
	
	public MangaStoryDetail(MangaStory mangaStory){
		super(mangaStory.getMangaId(),mangaStory.getLink(),mangaStory.getTitle(),mangaStory.getAuthor(), mangaStory.getImageLink(), mangaStory.getSummary());
		this.listChapters = new ArrayList<MangaChapter>();
	}
	
	public MangaStoryDetail() {
		// TODO Auto-generated constructor stub
		this.listChapters = new ArrayList<MangaChapter>();
	}
	
	public void setListChapters(List<MangaChapter> listChapters) {
		if(listChapters != null)
			this.listChapters = listChapters;
	}
	
	public List<MangaChapter> getListChapters() {
		return listChapters;
	}
	
	private List<MangaChapter> listChapters;
}
